/*
*私募管理人
*Home.js
*/
import React, { Component, PropTypes } from 'react';
import { connect } from 'dva';
import { routerRedux, Link, withRouter } from 'dva/router';
import { Row, Col, Button } from 'antd';
import Tabtitle from '../../../components/common/TabTitle';
import {
	PrivateNameInput,
	BranchOfficeChoice,
	BDepartmentChoice
} from '../components/SelectToolBar';
import AddPrivateMan from './component/AddPrivateMan';
import PrivateList from './component/ManagerTable';

// import DropdownRefresh from '../../../components/DropdownRefresh';
import style from './home.less';

let author;
const PrivateManager = ({ dispatch, privateMger,login, location: { pathname, query } }) => {
	const {
    privateData,
		privateName,
		departmentData,
		BOfficeCode,
		BDepartmentName,
		BOfficeId,
		
	} = privateMger;
	const {userInfo} = login;
	const tag = 'privateMger';
	const BOffice = [];
	const BDepartment = [];
	console.log('PrivateManager>', privateMger)
	if(!_.isEmpty(userInfo)){
		userInfo.authorities.map((i)=>{
			if(i == 'ROLE_HEADQUARTERSDOCKING' || i=='ROLE_ADMIN'){
				author='0'
			}else if(i == 'ROLE_BRANCHDOCKING'){
				author='2'
			}else{
				author='1'
			}
		})
	}
	function queryData() {
		if(privateName =='' && BOfficeId =='' && BDepartmentName==''){
			dispatch({
				type: 'privateMger/getsmmcAlxr',
				payload: {
					currentpage: 1,
					pagesize: 15,
				}
			})
		}else if(privateName !=='' && BOfficeId =='' && BDepartmentName==''){
			dispatch({
				type: 'privateMger/getsmmcAlxr',
				payload: {
					name: privateName,
					currentpage: 1,
					pagesize: 15,
				}
			})
		}else if(privateName =='' && BOfficeId !=='' && BDepartmentName ==''){
			dispatch({
				type: 'privateMger/getsmmcAlxr',
				payload: {
					departmentId:BOfficeId,
					currentpage: 1,
					pagesize: 15,
				}
			})
		}else if(privateName =='' && BOfficeId !=='' && BDepartmentName !==''){
			dispatch({
				type: 'privateMger/getsmmcAlxr',
				payload: {
					departmentId:BDepartmentName,
					currentpage: 1,
					pagesize: 15,
				}
			})
		}else if(privateName !=='' && BDepartmentName !=='' && BOfficeId !==''){
			dispatch({
				type: 'privateMger/getsmmcAlxr',
				payload: {
					name: privateName,
					departmentId:BDepartmentName,
					currentpage: 1,
					pagesize: 15,
				}
			})
		}else if(privateName !=='' && BDepartmentName =='' && BOfficeId !==''){
			dispatch({
				type: 'privateMger/getsmmcAlxr',
				payload: {
					name: privateName,
					departmentId:BOfficeId,
					currentpage: 1,
					pagesize: 15,
				}
			})
		}else if(privateName =='' && BDepartmentName =='' && BOfficeId !==''){
			dispatch({
				type: 'privateMger/getsmmcAlxr',
				payload: {
					departmentId:BOfficeId,
					currentpage: 1,
					pagesize: 15,
				}
			})
		}else if(privateName =='' && BDepartmentName !=='' && BOfficeId ==''){
			dispatch({
				type: 'privateMger/getsmmcAlxr',
				payload: {
					departmentId:BDepartmentName,
					currentpage: 1,
					pagesize: 15,
				}
			})
		}else if(privateName !=='' && BDepartmentName !=='' && BOfficeId ==''){
			dispatch({
				type: 'privateMger/getsmmcAlxr',
				payload: {
					name:privateName,
					departmentId:BDepartmentName,
					currentpage: 1,
					pagesize: 15,
				}
			})
		}
	}

	if(departmentData){
		departmentData.map((item,i)=>{
			if(item.parentId == 'ZZ001041'){
				BOffice.push(item)
			}
		})
	}
	
	if(BOfficeCode !==''){
  	departmentData.map((item)=>{
  		if(BOfficeCode == item.parentId){
  			BDepartment.push(item)
  		}
  	})
  }
  if(author=='2'&&!_.isEmpty(departmentData)){
  	departmentData.map((item)=>{
  		if(item.parentId !== "ZZ001041"){
  			BDepartment.push(item)
  		}
  	})
  }
	return (
		<div>
			<Tabtitle value={'私募管理人'} />
			<div className="page-privateMg-home content-inner">
				<div className={style.privateMgbtn}>
					<Row type="flex" justify="start" align="middle">
						<Col span={6}>
							<label>私募名称：</label>
							<PrivateNameInput
								tag={tag}
								dispatch={dispatch}
							/>
						</Col>
						{
							author=='0'&&BOffice!==[]?<Col span={4}>
								<label>分公司: </label>
								<BranchOfficeChoice
									value={BOfficeCode&&BOfficeCode!==''?departmentData.find(item=>item.code==BOfficeCode).name:'请选择分公司'}
									dispatch={dispatch}
									tag='privateMger'
									data={BOffice}
									allData={departmentData}
								/>
							</Col>:null
						}
						{
							BOfficeCode||BDepartment!==[]&&author=='2'?<Col span={5}>
								<label>营业部: </label>
								<BDepartmentChoice
									value={BDepartmentName&&BDepartmentName!==''?departmentData.find(item=>item.id==BDepartmentName).name:'请选择营业部'}
									dispatch={dispatch}
									tag='privateMger'
									data={BDepartment}
								/>
							</Col>:null
						}
						<Button type="primary" onClick={queryData}>查询</Button>
						{/*<AddPrivateMan/>*/}
					</Row>
					<Row type="flex" justify="start" align="middle">
						<AddPrivateMan />
					</Row>
				</div>
				{/*<div>*/}
				<div className={style.privateMglist}>
					<PrivateList />
				</div>
			</div>
		</div>
	)


}

PrivateManager.propTypes = {}

export default connect(({ privateMger,login }) => ({ privateMger,login }))(PrivateManager)